# Maintainer: Andy McLeod <andy@amcleod.ca>
pkgname=ejson
pkgver=1.2.1
pkgrel=4
pkgdesc="EJSON is a small library to manage encrypted secrets using asymmetric encryption."
url="https://github.com/Shopify/ejson"
arch="all"
license="MIT"
depends="mandoc" # Requires man to show help
makedepends="go ronn"
source="$pkgname-$pkgver.tar.gz::https://github.com/Shopify/$pkgname/archive/v$pkgver.tar.gz"

_gourl=github.com/Shopify/ejson
builddir="$srcdir"/src/$_gourl

prepare() {
	mkdir -p "${builddir%/*}"
	mv "$srcdir"/$pkgname-$pkgver "$builddir"
	default_prepare
}

build() {
	export GOPATH="$srcdir"
	CGO_ENABLED=0 go build -v -o e${pkgname} github.com/Shopify/ejson/cmd/ejson

	# Overwrite bundle exec so it runs our ronn command from the system not
	# from some rubygems repo
	sed -i 's|^BUNDLE_EXEC=.*|BUNDLE_EXEC=exec|' Makefile
	make man
}

check() {
	go test -v ./...
}

package() {
	install -Dm755 e${pkgname} "$pkgdir"/usr/bin/ejson

	# Keep this in the main package, ejson calls into 'man' to show
	# the help string
	mkdir -p "$pkgdir"/usr/share
	mv build/man "$pkgdir"/usr/share/man/
}
sha512sums="cd49e70b1578f0f960b6d6d77499297bcee7eac3b8595109757697ef844ba8867c353e257105af9b90fdbcca3a08445ae0c9b666c7bc6db26ab7303b5834c5bd  ejson-1.2.1.tar.gz"
